class Solution:
    """
    228. 汇总区间
    https://leetcode-cn.com/problems/summary-ranges/
    @date 2021年1月11日10:50:52
    @author mizzle rain
    """

    def summaryRanges(self, nums):
        n = len(nums)
        if n == 0:
            return []
        left, right = 0, 0
        res = []
        while right < n:
            while right + 1 < n and nums[right] == nums[right+1] - 1:
                right += 1
            res.append(f"{nums[left]}->{nums[right]}" if left != right else f"{nums[left]}")
            left, right = right + 1, right+1
        return res


if __name__ == "__main__":
    s = Solution()
    result = s.summaryRanges([0, 1, 2, 4, 5, 7])
    print(result)
